package LibDL.models;

import LibDL.recommender._BprRecommender;
import LibDL.supporting.CheckMemory;
import net.librec.common.LibrecException;
import net.librec.math.algorithm.Randoms;

import java.util.ArrayList;
import java.util.List;

public class BprBM {

    static {
        System.load(System.getProperty("user.dir") + "/../target/libLibDL.core.so");
    }

    public static void main(String[] args) throws LibrecException {

        CheckMemory.debug_countdown(5);

        // https://grouplens.org/datasets/movielens/10m/
        String train_root = "/benchmark/src/main/resources/ml-10M100K/ratings.dat";
        String test_root = "/benchmark/src/main/resources/ml-10M100K/ratings.dat";

        long t1 = System.currentTimeMillis();

        _BprRecommender bpr = (_BprRecommender) new _BprRecommender.Builder(
                "core/src/main/resources/datasets/ml1m/test/train.txt",
                "core/src/main/resources/datasets/ml1m/test/test.txt")
                .n_iter(4)
                .use_cuda(true)
                .data_split_rate(0.8)
                .data_convert_sep(" ")
                .rec_recommender_ranking_topn(10)
                .build();
        bpr.generateDataModel();
        bpr.trainModel(true);
        List<Integer> users = new ArrayList<Integer>();
        for(int i=0;i<30;i++) {
            int user_index = Randoms.uniform(6040);
            users.add(user_index);
        }
        bpr.predict(users,null);
        System.out.printf("Total time [%.2f s]\n", (float) (System.currentTimeMillis() - t1) / 1000);
    }
}
